package com.ccys.cms.controller.common;


import com.ccys.cms.service.CommonService;

import com.ccys.common.constants.TouristApi;

import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.CommonDto;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;


   /**
    * @description 公用接口
    * @date     2024/2/21
    * @author   cloud fly
    */
@RestController
@RequestMapping("/common")
@Api(tags = "公用")
public class CommonApiController {
    @Autowired
    private CommonService commonService;


    @GetMapping("/getSTSInfo")
    @ApiOperation("获取亚马逊S3上传凭证（没有角色ARN 暂不可用）")
    @TouristApi
    public ResponseResult getSTSInfo(@ApiIgnore CommonDto dto) {
        return this.commonService.getSTSInfo(dto);
    }


       @GetMapping("/getUploadUrl")
       @ApiOperation("为上传生成预签名 URL")
       @ApiImplicitParams({
           @ApiImplicitParam(name = "bucketName", value = "存储桶名称(prv.staging.whitecoat.global)", required = false, paramType = "query"),
           @ApiImplicitParam(name = "name", value = "文件名称", required = true, paramType = "query"),
       })
       @TouristApi
       public ResponseResult getUploadUrl(@ApiIgnore CommonDto dto) {
           return this.commonService.getUploadUrl(dto);
       }

       @GetMapping("/getDownloadUrl")
       @ApiOperation("为对象生成预签名下载 URL")
       @ApiImplicitParams({
           @ApiImplicitParam(name = "bucketName", value = "存储桶名称(prv.staging.whitecoat.global)", required = false, paramType = "query"),
           @ApiImplicitParam(name = "name", value = "文件名称", required = true, paramType = "query"),
       })
       @TouristApi
       public ResponseResult getDownloadUrl(@ApiIgnore CommonDto dto) {
           return this.commonService.getDownloadUrl(dto);
       }




    @ApiOperation("上传文件到亚马逊S3服务器")
    @TouristApi
    @RequestMapping(value="putS3ObjectByBase64",method= RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bucketName", value = "存储桶名称(prv.staging.whitecoat.global)", required = false, paramType = "query"),
        @ApiImplicitParam(name = "content", value = "Base64字符串", required = true, paramType = "query"),
    })
    public ResponseResult putS3ObjectByBase64(HttpServletRequest request,@ApiIgnore CommonDto dto){
        return this.commonService.putS3ObjectByBase64(request,dto);

    }
       /**
        * @description 上传文件到亚马逊S3服务器（multipart/form-data 方式）
        * @date     2024/2/21
        * @author   cloud fly
        */
       @ApiOperation("上传文件到亚马逊S3服务器（multipart/form-data 方式）")
       @TouristApi
       @RequestMapping(value="putS3ObjectByInputStream",method= RequestMethod.POST, headers = "content-type=multipart/form-data")
       @ApiImplicitParams({
           @ApiImplicitParam(name = "bucketName", value = "存储桶名称(prv.staging.whitecoat.global)", required = false, paramType = "query"),
           @ApiImplicitParam(name = "directory", value = "上传目录", required = false, paramType = "query"),
       })
       public ResponseResult putS3ObjectByInputStream(HttpServletRequest request,
                                         @ApiParam(value = "上传的文件", required = true)
                                         @RequestParam(value = "file", required = true) MultipartFile file, CommonDto dto){
           return this.commonService.putS3ObjectByInputStream(request,dto);

       }


       @ApiOperation("生成实体Id或Code")
       @TouristApi
       @RequestMapping(value="generateIdOrCode",method= RequestMethod.POST)
       @ApiImplicitParams({
           @ApiImplicitParam(name = "type", value = "0 生成member的code，1-生成医生code ", required = false, paramType = "query"),
       })
       public ResponseResult generateIdOrCode(HttpServletRequest request,@ApiIgnore CommonDto dto){
           return this.commonService.generateIdOrCode(request,dto);

       }

}
